package tests;
import java.util.Vector;

import tools.Help;

import network.dataFormats.NetworkPackage;
import network.dataFormats.PackageType;
import network.protocol.PackageSplitter;
public class SplitTest {
	/**
	 * @author toni
	 * 
	 * @param args
	 */
	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		PackageSplitter s = new PackageSplitter();
		Vector<NetworkPackage> p = new Vector<NetworkPackage>();
		Vector<NetworkPackage> cl = (Vector<NetworkPackage>) p.clone();
		for (int i = 0; i < 300; i++) {
			p.add(new NetworkPackage(PackageType.INIT, new byte[10000 + i * PackageSplitter.ALLOWEDSIZE], i, 0.0f));
		}
		p = s.splitBigPackages(p);
		Vector<NetworkPackage> r = new Vector<NetworkPackage>();
		while (!p.isEmpty()) {
			Vector<NetworkPackage> f = new Vector<NetworkPackage>();
			int raa = (int) (p.size() * Math.random());
			f.add(p.get(raa));
			p.remove(raa);
			r.addAll(s.joinSplitPackages(f));
		}
		Help.p(r);
		for (NetworkPackage k : r) {
			boolean contains = false;
			for (NetworkPackage f : cl) {
				if (f.bytes.length == k.bytes.length && f.header.type == k.header.type)
					contains = true;
			}
			assert (contains);
		}
	}
}
